﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Manul.Genetics.Compiler;

namespace Manul.Interface.TreeNodes
{
    public class ObjectTreeNode<T> : TreeNode, ICountableTreeNode where T : new()
    {
        public ObjectTreeNode()
        {
            _obj = new T();
        }
        public ObjectTreeNode(T obj)
        {
            AttachObject(obj);
        }

        private T _obj;
        public T Obj
        {
            get
            {
                return _obj;
            }
        }
        public void AttachObject(T obj)
        {
            _obj = obj;
        }

        #region ICountableTreeNode Members

        public int UpdateRealCharacterItemsCount<U, V>()
            where U : ICountableTreeNode
            where V : ICountableTreeNode
        {
            realCharacterCount = 0;
            foreach (TreeNode node in this.Nodes)
            {
                if (node is U)
                    realCharacterCount += ((ICountableTreeNode)node).UpdateRealCharacterItemsCount<U, V>();
                else if (node is V)
                    realCharacterCount++;
            }
            return realCharacterCount;
        }
        private int realCharacterCount = 0;
        public int RealCharacterCount
        {
            get { return realCharacterCount; }
        }
        #endregion
    }
}
